<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function set_blue_text($string, $start=1, $count=NULL)
{
	$words = explode(" ", $string);
	
	if($count == NULL) {
		$count = count($words)-1;
	}
	else if ($count != NULL && $count < 0) {
		$count = $start;
	}
	else if ($count != NULL && $count > count($words)) {
		$count = count($words)-1;
	}
	
	$before	= "";
	$after	= "";
	$blue	= "";
	
	
	
	// before blue
	for($i = 0; $i < ($start-1); $i++) {
		$before .= $words[$i] . " ";
	}

	//echo "<br>before: $before";
	
	// blue
	for($i = ($start-1); $i<($start+$count-1); $i++) {
		$blue .= $words[$i] . " ";
	}
	//echo "<br>blue: $blue";
	
	// after blue
	for($i = ($start+$count-1); $i<count($words); $i++) {
		$after .= $words[$i] . " ";
	}
	//echo "<br>after: $after";
	
	return ($before . "<span class=\"blue\">" . $blue . "</span>" . $after);
	
}

/*
 	===== TEST =====
	echo set_blue_text("test blue text with first word") . "<br/>";
    echo set_blue_text("test blue text with first word again", 1) . "<br/>";
    echo set_blue_text("test blue text with random word [3]", 3) . "<br/>";
    echo set_blue_text("test blue text with four firsts words", 1, 4) . "<br/>";
    echo set_blue_text("test blue text with two random words [4-7]", 4, 7) . "<br/>";
    echo set_blue_text("test blue text with error", 6, 2) . "<br/>"; 
    ===== ==== =====
*/

/* End of file text_format_helper.php */
/* Location: ./application/helpers/text_format_helper.php */
?>